package cn.edu.nju.software.zp13.core.nodeGenerator;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import cn.edu.nju.software.zp13.core.nodeDescriptor.NodeDescriptor;
import cn.edu.nju.software.zp13.core.xmlNodeEntity.XmlNodeEntity;

public class ArrayComplexNodeGenerator extends NodeGenerator {

	public ArrayComplexNodeGenerator(Document dom) {
		super(dom);
	}

	@Override
	public void updateDom(Node node, NodeDescriptor descriptor) {
		String nodeName = descriptor.getNodeName();
		XmlNodeEntity[] entities = getArrayEntitiesContent(descriptor);
		if (nodeName == null) {
			updateNode(node, entities);
		} else {
			Element e = dom.createElement(nodeName);
			updateNode(e, entities);
			node.appendChild(e);
		}
	}

	private void updateNode(Node node, XmlNodeEntity[] entities) {
		for (XmlNodeEntity entity : entities) {
			node.appendChild(entity.toXmlNode(dom));
		}
	}

}
